﻿using System.Linq;
using System.Windows;
using System.Windows.Media;

namespace RainwaterTankEstimator
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        #region Properties

        public int RoofArea
        {
            get;
            private set;
        }

        public int TankSize
        {
            get;
            private set;
        }

        public int WaterUse
        {
            get;
            private set;
        }

        public float Efficiency
        {
            get;
            private set;
        }

        public int FirstFlush
        {
            get;
            private set;
        }

        #endregion

        public MainWindow()
        {
            InitializeComponent();

            this.Efficiency = 80;
            this.FirstFlush = 1;
            this.InputPanel.DataContext = this;
        }

        // Handle button click
        private void VisualizeClick(object sender, RoutedEventArgs e)
        {
            if (this.TankSize > 0 && this.WaterUse > 0 && this.RoofArea > 0)
            {
                var est = new Estimator(this.RoofArea, this.TankSize, this.WaterUse, this.FirstFlush, this.Efficiency * 0.01F);
                est.ReadFile("rain_days.csv");

                var m = new MainChartViewModel(est.Months.Select(x => x.Data));
                this.MainChart.DataContext = m;

                var s = new SecondChartViewModel(est.DemandMet);

                this.MonthChart.DataContext = est;
                this.SecondChart.DataContext = s;
                this.DemandChartMonthly.DataContext = est;

                this.ErrorBox.Text = "Charts generated";
                this.ErrorBox.Foreground = Brushes.MidnightBlue;
            }
            else
            {
                this.ErrorBox.Text = "Values must be nonzero and nonnegative";
                this.ErrorBox.Foreground = Brushes.Firebrick;
            }
        }
    }
}
